package com.china08.yxyapi.api.manage.tec.office.website.article;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class SwsTeaArticleAuthService {

    @Autowired
    private RestTemplate restTemplate;

    @Value("${yx.rest.api.yx.path}")
    public String yxApi;

    @Value("${spring.profiles.active}")
    String profiles;

    public boolean isTeacherArticleAuth(String userId, String schoolId) {
        String api = "/comm/tea/isautharticle";
        if (StringUtils.equals("dev", profiles)) {
            api = "http://localhost:9083/api_yx" + api;
        } else if (StringUtils.equals("test", profiles)) {
            api = "http://192.168.2.101/api_yx" + api;
        } else {
            api = yxApi + api;
        }
        ReqModel reqModel = new ReqModel();
        reqModel.userId = userId;
        reqModel.schoolId = schoolId;
        RespModel model = restTemplate.postForObject(api, reqModel, RespModel.class);
        return model.isAuth;
    }

    protected static class ReqModel {
        public String userId;
        public String schoolId;
    }

    protected static class RespModel {
        // true授权 false未授权
        public boolean isAuth;
    }

}
